using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;

namespace Pay.Service.AutoMapper {
	public class BulletinMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public BulletinMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<bulletin_dto, Bulletin>()
				.ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
				.ForMember(dest => dest.Title, src => src.MapFrom(c => c.title))
				.ForMember(dest => dest.Content, src => src.MapFrom(c => c.content))
				.ForMember(dest => dest.ShortContent, src => src.MapFrom(c => c.short_content))
				.ForMember(dest => dest.ImagePath, src => src.MapFrom(c => c.image_path))
				.ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
				.ForMember(dest => dest.Status, src => src.MapFrom(c => c.status));
			_cfg.CreateMap<Bulletin, bulletin_dto>()
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
				.ForMember(dest => dest.title, src => src.MapFrom(c => c.Title))
				.ForMember(dest => dest.content, src => src.MapFrom(c => c.Content))
				.ForMember(dest => dest.short_content, src => src.MapFrom(c => c.ShortContent))
				.ForMember(dest => dest.image_path, src => src.MapFrom(c => c.ImagePath))
				.ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
				.ForMember(dest => dest.status, src => src.MapFrom(c => c.Status));
		}
	}
}
